/*
 * $Id: cond.h,v 1.2 2005-12-16 18:19:15 bacon Exp $
 */

#ifndef _XP_BAS_COND_H_
#define _XP_BAS_COND_H_

#include <xp/types.h>
#include <xp/macros.h>
#include <xp/bas/thr.h>
#include <xp/bas/mtx.h>
#include <xp/bas/time.h>

/*
 * TYPE: xp_cond_t
 *   Defines a condition object
 */
typedef struct xp_cond_t xp_cond_t;

struct xp_cond_t
{
#ifdef _WIN32
	void* gate;
	void* queue;
	void* mutex;
	unsigned int  gone;
	unsigned long blocked;
	unsigned int  waiting;
#else
	pthread_cond_t hnd;
#endif
	xp_bool_t __dynamic;
};

#ifdef __cplusplus
extern "C" {
#endif

/* 
 * FUNCTION: xp_cond_open
 */
xp_cond_t* xp_cond_open (xp_cond_t* cond);

/*
 * FUNCTION: xp_cond_close
 */
void xp_cond_close (xp_cond_t* cond);

/*
 * FUNCTION: xp_cond_signal
 */
void xp_cond_signal (xp_cond_t* cond);

/*
 * FUNCTION: xp_cond_broadcast
 */
void xp_cond_broadcast (xp_cond_t* cond);

/*
 * FUNCTION: xp_cond_wait
 */
void xp_cond_wait (xp_cond_t* cond, xp_mtx_t* mutex);

/*
 * FUNCTION: xp_cond_twait
 */
void xp_cond_twait (
	xp_cond_t* cond, xp_mtx_t* mutex, xp_time_t waiting_time);

#ifdef __cplusplus
}
#endif

#endif
